<?php
/**
 * @author baby&star
 *
 *
 */
class TestproductsController extends Controller{
	//TODO - Insert your code here
	function actionIndex(){
		//echo Yii::app()->controller->action->id;
		
		$wh = "";
		if($_POST){
			$wh = " and `name` like '%".$_POST['keyword']."%'";
		}
		$page = isset($_GET["page"])&&$_GET["page"]>0?$_GET["page"]:1;
		$brand = new brand_products();
		$data = $brand->getList("`deleted` = 0 ".$wh,"id desc",$page,$this->createUrl("testproducts/index"),6);
		
		//print_r($data);
		$this->render("index",array("data"=>$data));
		
	}
	
	function actionConfirm(){
		if($_POST){
			$ids = $_POST["ids"];
			if(empty($ids)){
				echo 0;
				exit;
			}
			$brand = new brand_products();
			
			
			$rs = $brand->getAll(" id in (".$ids.") and `isUsed` = 0");
			
			$products = $brand;
			
			foreach($rs as $k=>$v){
				$products->setName("products");
				$arr = array("shopId"=>'',"brandId"=>$v["brandId"],
					"name"=>$v["name"],
					"price"=>$v["price"],
					"imgPath"=>$v["imgPath"],
					"detailHref"=>$v["detailHref"],
					"deleted"=>0
				);
				$products->insertData($arr);
				//更新状态
				$arr = array("isUsed"=>1);
				$brand->setName("brand_products");
				$brand->updateData($arr, "`id`='".$v['id']."'");
			}
			echo 1;
			exit;
		}
		echo 0;
		exit;
	}
	function actionDelete(){
		$id = $_GET["id"];
		if(!is_numeric($id)){
			Common::jsalerturl("非法操作！");
			exit;
		}
		$brand = new brand_products();
		
		$brand->del("`id` = '".$id."'");
		Common::jsalerturl("删除成功！");
	}
}


?>